// init.js

/* block users with unsupported browser */
if( typeof(Storage) == undefined )
{
	alert("This web app is not supported with your browser.");
	window.location.href = "http://google.com/chrome"; // redirect to chrome site
} 

/* check if this is the user's first visit */
var isNewUser = localStorage.getItem("user") == null;

if( isNewUser ) {
	User.write( new User() ); // write empty user to localStorage

	/* show introduction */
	$(document).ready(function() {
		var INTRO = '<h1>Welcome to Cookie Flix</h1>';
		INTRO += '<p>Cookie Flix allow you to rent movies, then recommends '
			+ 'movies to you based on your activity. Every time you view a movie\'s '
			+ 'details, click "like" on a movie box, or rent a movie, you update your '
			+ 'user profile. However, there is no need to register. Everything is stored '
			+ 'in a cookie on your machine. (Well, not really a cookie. Data is stored in '
			+ 'the localStorage object).</p><p>For more information, check out our blog.</p>';
	
		$("#profile").html( INTRO );
	});
}	

/*
 * Configure the site to obtain images from TMDB
 */
 
/* global configurations object */
var configs = {};

//!!! change this to the root directory of the site on your machine
configs.site_base_url = 'http://cookieflix.site88.net/';

jQuery.getJSON(
	'http://api.themoviedb.org/3/configuration',
	{
		api_key: '8974c48b90e1fd0f122e66481cb737ad'
	},
	function(response) {
		//console.log(JSON.stringify(response, null, 4));
		configs.images = response.images;
	}
);
